/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RealizarTareaView.java
 *
 * Created on 16-ene-2011, 17:26:15
 */

package Vista.TareaRealizada;

import Modelo.Entidades.RespuestaContestada;
import Modelo.Entidades.TareaRealizada;
import Modelo.PDF;

/*
 *  Proyecto eJAM [G12]
 *  Miembros:
 *      - Javier Ruiz Hidalgo
 *      - Adrian Ramos Cápitas
 *      - Miguel Alejandro Esteban Ordóñez
 */

public class ConsultaTareaRealizadaView extends javax.swing.JFrame {

    private TareaRealizada tareaRealizada;
    private TareaRealizadaConsultaViewTableModel tareaRealizadaConsultaViewTableModel;
    private RespuestaConcretaTableModel respuestaConcretaTableModel;


    /** Creates new form RealizarTareaView */
    public ConsultaTareaRealizadaView(TareaRealizada tareaRealizada) {
        this.tareaRealizada = tareaRealizada;
        this.tareaRealizadaConsultaViewTableModel = TareaRealizadaConsultaViewTableModel.create();
        this.respuestaConcretaTableModel = RespuestaConcretaTableModel.create();

        initComponents();

        this.setVisible(true);

        this.jNombreTarea.setText(this.tareaRealizada.getTarea().getNombre());
        this.jNota.setText(String.valueOf(this.tareaRealizada.getNota()));
        refreshPreguntas();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelPreguntas = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablaPreguntasContestadas = new javax.swing.JTable();
        jPanelRespuestas = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTablaRespuestasContestadas = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        jNota = new javax.swing.JLabel();
        jNombreTarea = new javax.swing.JLabel();
        jCerrar = new javax.swing.JButton();
        jPDF = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Realización de Tarea");

        jPanelPreguntas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resumen de Preguntas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jTablaPreguntasContestadas.setModel(tareaRealizadaConsultaViewTableModel);
        jTablaPreguntasContestadas.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTablaPreguntasContestadas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTablaPreguntasContestadasMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTablaPreguntasContestadas);

        javax.swing.GroupLayout jPanelPreguntasLayout = new javax.swing.GroupLayout(jPanelPreguntas);
        jPanelPreguntas.setLayout(jPanelPreguntasLayout);
        jPanelPreguntasLayout.setHorizontalGroup(
            jPanelPreguntasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelPreguntasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelPreguntasLayout.setVerticalGroup(
            jPanelPreguntasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPreguntasLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanelRespuestas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Resumen de Respuestas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jTablaRespuestasContestadas.setModel(respuestaConcretaTableModel);
        jScrollPane2.setViewportView(jTablaRespuestasContestadas);

        javax.swing.GroupLayout jPanelRespuestasLayout = new javax.swing.GroupLayout(jPanelRespuestas);
        jPanelRespuestas.setLayout(jPanelRespuestasLayout);
        jPanelRespuestasLayout.setHorizontalGroup(
            jPanelRespuestasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelRespuestasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 748, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelRespuestasLayout.setVerticalGroup(
            jPanelRespuestasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRespuestasLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Nota"));

        jNota.setFont(new java.awt.Font("Arial Black", 0, 12));
        jNota.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jNota, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jNota, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE)
                .addContainerGap())
        );

        jNombreTarea.setFont(new java.awt.Font("Calibri", 3, 24));
        jNombreTarea.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jCerrar.setText("Cerrar");
        jCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCerrarActionPerformed(evt);
            }
        });

        jPDF.setText("Exportar a PDF");
        jPDF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPDFActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelRespuestas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jNombreTarea, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanelPreguntas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPDF, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jNombreTarea, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelPreguntas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelRespuestas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCerrar)
                    .addComponent(jPDF))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTablaPreguntasContestadasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTablaPreguntasContestadasMouseClicked
        TareaRealizadaConsultaViewTableModel trcvtm = (TareaRealizadaConsultaViewTableModel)this.jTablaPreguntasContestadas.getModel();
        RespuestaContestada respuestaContestada = trcvtm.getRow(this.jTablaPreguntasContestadas.getSelectedRow());
        
        refreshRespuestas(respuestaContestada);
    }//GEN-LAST:event_jTablaPreguntasContestadasMouseClicked

    private void jCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCerrarActionPerformed
        this.dispose();
    }//GEN-LAST:event_jCerrarActionPerformed

    private void jPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPDFActionPerformed
        PDF.getInstance().pdf(this.tareaRealizada.getAlumno().getDNI() + " " + this.tareaRealizada.getTarea().getNombre(), this.tareaRealizada.toString());
    }//GEN-LAST:event_jPDFActionPerformed

    /**
    * @param args the command line arguments
    */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCerrar;
    private javax.swing.JLabel jNombreTarea;
    private javax.swing.JLabel jNota;
    private javax.swing.JButton jPDF;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelPreguntas;
    private javax.swing.JPanel jPanelRespuestas;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTablaPreguntasContestadas;
    private javax.swing.JTable jTablaRespuestasContestadas;
    // End of variables declaration//GEN-END:variables

    private void refreshPreguntas() {
        this.tareaRealizadaConsultaViewTableModel.setTareaRealizada(tareaRealizada);
    }

    private void refreshRespuestas(RespuestaContestada respuestaContestada) {
        this.respuestaConcretaTableModel.setRespuestasContestadas(respuestaContestada);
    }

}
